<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------

namespace Lg\Log;

use Monolog\Logger as Monologger;

/**
 * Description of Logger
 *
 * @author Allen <allen@lg4.cn>
 */
class Logger {

    /**
     * The Monolog logger instance.
     *
     * @var \Monolog\Logger
     */
    protected $monolog;

    /**
     * Detailed debug information
     */
    const DEBUG = Monologger::DEBUG;

    /**
     * Interesting events
     *
     * Examples: User logs in, SQL logs.
     */
    const INFO = Monologger::INFO;

    /**
     * Uncommon events
     */
    const NOTICE = Monologger::NOTICE;

    /**
     * Exceptional occurrences that are not errors
     *
     * Examples: Use of deprecated APIs, poor use of an API,
     * undesirable things that are not necessarily wrong.
     */
    const WARNING = Monologger::WARNING;

    /**
     * Runtime errors
     */
    const ERROR = Monologger::ERROR;

    /**
     * Critical conditions
     *
     * Example: Application component unavailable, unexpected exception.
     */
    const CRITICAL = Monologger::CRITICAL;

    /**
     * Action must be taken immediately
     *
     * Example: Entire website down, database unavailable, etc.
     * This should trigger the SMS alerts and wake you up.
     */
    const ALERT = Monologger::ALERT;

    /**
     * Urgent alert.
     */
    const EMERGENCY = Monologger::EMERGENCY;

    protected $levels = [
        'debug' => Monologger::DEBUG,
        'info' => Monologger::INFO,
        'notice' => Monologger::NOTICE,
        'warning' => Monologger::WARNING,
        'error' => Monologger::ERROR,
        'critical' => Monologger::CRITICAL,
        'alert' => Monologger::ALERT,
        'emergency' => Monologger::EMERGENCY,
    ];

 
    public function __construct($log) {
        $this->monolog = $log;
    }

    public function debug($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function info($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function notice($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function warning($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function error($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function critical($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function alert($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function emergency($message, $context = []) {
        $this->write(__FUNCTION__, $message, $context);
    }

    public function write($level, $message, $context = []) {
        $this->monolog->{$level}($message, $context);
    }

    /**
     * Get the Monolog instance.
     *
     * @return \Monolog\Logger
     */
    public function getLogger() {
        return $this->monolog;
    }

}
